package logic

import (
	"context"
	"errors"
	"shop/internal/svc"
	"shop/model/mysql"
	"shop/shop"
	"shop/shopclient"
	"strconv"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUserListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserListLogic {
	return &UserListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UserListLogic) UserList(in *shop.UserListRequest) (*shop.UserListResponse, error) {
	// todo: add your logic here and delete this line

	var a mysql.User
	a.ID = uint(in.UserId)
	var users []mysql.User
	var userList []*shopclient.UserList
	mysql.DB.Find(&users)
	for _, user := range users {
		if user.Status != 2 && user.Status != 3 {
			logx.Error("用户状态不正确")
			return nil, errors.New("用户状态不正确")
		}
		userList = append(userList, &shopclient.UserList{
			Mobile:   user.Mobile,
			Password: user.Password,
			Stauts:   strconv.Itoa(user.Status),
		})
	}
	return &shop.UserListResponse{
		Liat: userList,
	}, nil
}
